import * as actionType from './constants.js';
import { reqhome } from '../../../api/index'


export const InsertHomeData = (data) => ({
    // console.log("进去成功...............");
    type: actionType.CHANGE_HOMEDATA,
    data: data
})

export const getHomeData = () => {
    return (dispatch) => {
        reqhome()
            .then((res) => {
                dispatch(InsertHomeData(res.data.data))
            })
            .catch((e) => {
                console.log('出错了');
            })
    }
}

export const InsertShopcar = (data) => ({
    type: actionType.CHANGE_SHOPCAR,
    data: data
})

export const IncrementShopcarNum = (data) => ({
    type: actionType.INCREMENT_NUM,
    data: data
})

export const DecrementShopcarNum = (data) => ({
    type: actionType.DECREMENT_NUM,
    data: data
})

export const changeCheck = (data) => ({
    type: actionType.CHANGE_CHECK,
    data: data
})

export const changeAll = (data) => {
    return (dispatch) => {
        // total?

        dispatch({
            type: actionType.CHANGE_ALL,
            data: data

        })
        dispatch(countAll(data))
    }
}

export const countAll = (data) => ({
    type: actionType.COUNT_ALL,
    data: data
})